import { request } from './request';

export function getRolesData() {
  return request({
    url: 'roles'
  });
}

export function addRolesData(addRolesForm) {
  return request({
    method: 'post',
    url: 'roles',
    data: addRolesForm
  });
}

export function queryRolesData(roleId) {
  return request({
    url: `roles/${roleId}`
  });
}

export function submitRolesData(editRolesForm) {
  return request({
    method: 'put',
    url: `roles/${editRolesForm.roleId}`,
    data: editRolesForm
  });
}

export function deleteRole(roleId) {
  return request({
    method: 'delete',
    url: `roles/${roleId}`
  });
}

export function deleteRights(roleId, rightId) {
  return request({
    method: 'delete',
    url: `roles/${roleId}/rights/${rightId}`
  });
}

export function getRightsList() {
  return request({
    url: 'rights/tree'
  });
}

export function updateRights(roleId, idObj) {
  return request({
    method: 'post',
    url: `roles/${roleId}/rights`,
    data: idObj
  });
}

export function assignUserRole(userId, rid) {
  return request({
    method: 'put',
    url: `users/${userId}/role`,
    data: {rid}
  });

}